﻿(function (win) {
    // 다음API 객체 등록
    var Dkey = "7ec8f88c9d9e1b2dbad869af9a47c8ea510b7917";
    var D = win.D = {};

    // 쿼리, 페이지
    D.Send = function (q, p, f) {

        this.res = function (z) {
            f.call(win, z.channel.item, z.channel.totalCount);
        };

        this.s = document.createElement('script');
        this.s.type = 'text/javascript';
        this.s.charset = 'utf-8';
        this.s.src = 'http://apis.daum.net/shopping/search?apikey=' + Dkey +
			'&output=json&callback=D.res&q=' + encodeURI(q) + '&pageno=' + p;
        document.getElementsByTagName('head')[0].appendChild(this.s);
    };

    var N = win.N = {};

    // 단축url
    N.Send = function (u, f) {
        var req;
        var src = "/Goods/NaverProxy?url=" + encodeURIComponent(u);

        if (window.XMLHttpRequest) {
            req = new XMLHttpRequest();
            if (req) {
                req.onreadystatechange = function () {
                    if (req.readyState == 4 && req.status == 200) {
                        if (req.status == 200) {
                            f.call(win, req.responseText);
                        }
                        else {
                            alert("XDomainRequest.error : " + req.statut);
                        }
                    }
                };
                req.open('get', src, true);
                req.send();
            }
            else {
                alert("XMLHttpRequest 생성에러");
            }
        }
        else {
            alert("Browser update please...");
        }
    }

})(this);
